package Jets.ui
{
   import flash.display.DisplayObjectContainer;
   import flash.display.Sprite;
   import flash.events.Event;
   import flash.events.MouseEvent;
   import flash.geom.Rectangle;
   
   public class JScrollPanel extends JPanel
   {
      
      public function JScrollPanel(param1:DisplayObjectContainer=null, param2:Number=0, param3:Number=0, param4:String="") {
         super(param1,param2,param3,param4);
         this.mClientAreaScrollV = 0;
         this.mClientAreaScrollH = 0;
         this.mbEnableVScroll = true;
         this.mbEnableHScroll = true;
      }
      
      protected var mClientAreaView:Sprite;
      
      protected var mClientAreaContent:JPanel;
      
      protected var mbShowVScrollBar:Boolean;
      
      protected var mVScrollBar:JVScorllBar;
      
      protected var mbShowHScrollBar:Boolean;
      
      protected var mHScrollBar:JHScrollBar;
      
      protected var mClientAreaViewWidth:int;
      
      protected var mClientAreaViewHeight:int;
      
      protected var mClientAreaScrollV:Number;
      
      protected var mClientAreaScrollH:Number;
      
      protected var mbEnableVScroll:Boolean;
      
      protected var mbEnableHScroll:Boolean;
      
      public function setShowVScrollBar(param1:Boolean) : void {
         if(this.mbShowVScrollBar != param1)
         {
            this.mbShowVScrollBar = param1;
            invalidate();
         }
      }
      
      public function setShowHScrollBar(param1:Boolean) : void {
         if(this.mbShowHScrollBar != param1)
         {
            this.mbShowHScrollBar = param1;
            invalidate();
         }
      }
      
      public function set enableVScroll(param1:Boolean) : void {
         this.mbEnableVScroll = param1;
      }
      
      public function set enableHScroll(param1:Boolean) : void {
         this.mbEnableHScroll = param1;
      }
      
      override protected function addChildren() : void {
         super.addChildren();
         skin = null;
         this.mClientAreaView = new Sprite();
         this.mClientAreaView.addEventListener(MouseEvent.MOUSE_WHEEL,this.onMouseWheel);
         addChild(this.mClientAreaView);
         this.updateClientAreaViewScrollRect();
         this.mClientAreaContent = new JPanel(this.mClientAreaView);
         this.mClientAreaContent.skin = "";
         this.mClientAreaContent.setSize(this.mClientAreaViewWidth,this.mClientAreaViewHeight);
         this.mVScrollBar = new JVScorllBar(this,this.mClientAreaViewWidth,0,this.onScroll);
         this.mVScrollBar.setSize(JScrollBar.DefaultWidth,this.mClientAreaViewHeight);
         this.mVScrollBar.value = 100;
         this.mVScrollBar.visible = this.mbShowVScrollBar;
         this.mHScrollBar = new JHScrollBar(this,0,this.mClientAreaViewHeight,this.onScroll);
         this.mHScrollBar.setSize(this.mClientAreaViewWidth,JScrollBar.DefaultHeight);
         this.mHScrollBar.value = 0;
         this.mHScrollBar.visible = this.mbShowHScrollBar;
      }
      
      override public function setSize(param1:Number, param2:Number) : void {
         super.setSize(param1,param2);
         invalidate();
      }
      
      override public function draw() : void {
         super.draw();
         this.mClientAreaViewWidth = width;
         if(this.mbShowVScrollBar)
         {
            this.mClientAreaViewWidth = this.mClientAreaViewWidth - JScrollBar.DefaultWidth;
         }
         this.mClientAreaViewHeight = height;
         if(this.mbShowHScrollBar)
         {
            this.mClientAreaViewHeight = this.mClientAreaViewHeight - JScrollBar.DefaultHeight;
         }
         if(this.mClientAreaView)
         {
            this.updateClientAreaViewScrollRect();
         }
         if(this.mVScrollBar)
         {
            this.mVScrollBar.x = this.mClientAreaViewWidth;
            this.mVScrollBar.setSize(JScrollBar.DefaultWidth,this.mClientAreaViewHeight);
            this.mVScrollBar.visible = this.mbShowVScrollBar;
         }
         if(this.mHScrollBar)
         {
            this.mHScrollBar.y = this.mClientAreaViewHeight;
            this.mHScrollBar.setSize(this.mClientAreaViewWidth,JScrollBar.DefaultHeight);
            this.mHScrollBar.visible = this.mbShowHScrollBar;
         }
      }
      
      public var scrollCallback:Function;
      
      protected function onScroll(param1:Event) : void {
         var _loc2_:Number = (this.mVScrollBar.maximum - this.mVScrollBar.value) / (this.mVScrollBar.maximum - this.mVScrollBar.minimum);
         this.scrollVPercent = _loc2_;
         var _loc3_:Number = (this.mHScrollBar.value - this.mHScrollBar.minimum) / (this.mHScrollBar.maximum - this.mHScrollBar.minimum);
         this.scrollHPercent = _loc3_;
         if(null != this.scrollCallback)
         {
            this.scrollCallback(_loc2_,_loc3_);
         }
      }
      
      protected function onMouseWheel(param1:MouseEvent) : void {
         var _loc2_:int = this.scrollV - param1.delta * 3;
         var _loc3_:int = this.maxScrollV;
         if(_loc2_ < 0)
         {
            _loc2_ = 0;
         }
         else
         {
            if(_loc2_ > _loc3_)
            {
               _loc2_ = _loc3_;
            }
         }
         this.scrollV = _loc2_;
         var _loc4_:Number = Number(_loc2_) / _loc3_;
         this.mVScrollBar.value = this.mVScrollBar.maximum + (this.mVScrollBar.minimum - this.mVScrollBar.maximum) * _loc4_;
      }
      
      public function get clientArea() : JPanel {
         return this.mClientAreaContent;
      }
      
      public function get scrollV() : Number {
         return this.mClientAreaScrollV;
      }
      
      public function set scrollV(param1:Number) : void {
         if((this.mbEnableVScroll) && !(this.mClientAreaScrollV == param1))
         {
            this.mClientAreaScrollV = param1;
            invalidate();
         }
      }
      
      public function set scrollVPercent(param1:Number) : void {
         this.scrollV = this.maxScrollV * param1;
      }
      
      public function get maxScrollV() : Number {
         var _loc1_:Number = this.mClientAreaContent.getBounds(this).height - this.mClientAreaViewHeight;
         return _loc1_ < 0?0:_loc1_;
      }
      
      public function get scrollH() : Number {
         return this.mClientAreaScrollH;
      }
      
      public function set scrollH(param1:Number) : void {
         if((this.mbEnableHScroll) && !(this.mClientAreaScrollH == param1))
         {
            this.mClientAreaScrollH = param1;
            invalidate();
         }
      }
      
      public function set scrollHPercent(param1:Number) : void {
         this.scrollH = this.maxScrollH * param1;
      }
      
      public function get maxScrollH() : Number {
         var _loc1_:Number = this.mClientAreaContent.getBounds(this).width - this.mClientAreaViewWidth;
         return _loc1_ < 0?0:_loc1_;
      }
      
      protected function updateClientAreaViewScrollRect() : void {
         var _loc1_:Rectangle = new Rectangle(this.mClientAreaScrollH,this.mClientAreaScrollV,this.mClientAreaViewWidth,this.mClientAreaViewHeight);
         this.mClientAreaView.scrollRect = _loc1_;
      }
   }
}
